#!/usr/bin/env python3
# -*- coding:utf-8 -*-

'python没有任何机制强制限制编程，一切全靠自觉'


class Student(object):  # object表示该类从哪个类继承
    # __slots__ = ("name","age","addTimes","__name", "__age")
    # 好像会导致school变成只读属性？？
    school = "学校"

    def __init__(self, name, age):
        self.__name = name  # __开头的是私有变量
        self.__age = age

    def printStu(self):
        print("学生类 printStu：name:%s,age:%s" % (self.__name, self.__age))

    @property   # 类似于将一队get set函数变换成了对象 不定义setter就是只读对象
    def name(self):
        return self.__name

    @name.setter
    def name(self, name):
        if not isinstance(name, str):
            raise AttributeError("名称必须为字符串")
        self.__name = name

    def __dir__(self):
        print("重写系统dir函数")
        return [10, 20, 30]


class MiniStu(Student):
    def __init__(self, name, age, sex):
        super().__init__(name, age)
        self.sex = sex

    def printStu(self):
        print(__doc__)
        super().printStu()
        print("小学生类 printStu：sex:", self.sex)


class NoStu(object):
    def printStu(self):
        print("非学生类：NoStu printStu")


# 练习
class Screen(object):  # property的字段不能与原字段相同,否则会递归过多报错
    def __init__(self):
        self.widthS = 1024
        self.heightS = 768

    @property
    def width(self):
        return self.widthS

    @width.setter
    def width(self, width):
        self.widthS = width

    @property
    def height(self):
        return self.heightS

    @height.setter
    def height(self, height):
        self.heightS = height

    @property
    def resolution(self):
        return self.widthS * self.heightS
